using System;
using System.Collections.Generic;
using System.Text;
using Petra.Gis;
using Petra.Gis.Geometry;
using Petra.Gis.Geometry.Support;
using Petra.Gis.DataServices.WKB.Support;
using System.IO;

namespace Petra.Gis.DataServices.WKB
{
  public partial class GeometryFactory
  {
    /***********************************************
     * 28.8.2007
     * 
     * creates intergraph blob structure 
     * from GeometryCollection
     * 
     * asida@centrum.cz, initial implementation
     *************************************************/

    private static byte[] multiPointToBinary(GeometryBase geometry)
    {
      //cast to MultiPoint first
      MultiPoint _coll = (MultiPoint)geometry;

      System.IO.MemoryStream oIMStream = new System.IO.MemoryStream();
      System.IO.BinaryWriter mBWriter = new System.IO.BinaryWriter(oIMStream);

      oIMStream.Position = 0;

      mBWriter.Write((byte)EndianConverter.GetCurrentPlatformEndian());
      mBWriter.Write((Int32)WKB.WKBGeometryTypes.MultiPoint);

      mBWriter.Write(collectionItemsToBinary(_coll, 0));
      return oIMStream.ToArray();
    }



    private static byte[] multiLineToBinary(GeometryBase geometry)
    {
      //cast to MultiLine first
      MultiLine _coll = (MultiLine)geometry;

      System.IO.MemoryStream oIMStream = new System.IO.MemoryStream();
      System.IO.BinaryWriter mBWriter = new System.IO.BinaryWriter(oIMStream);

      oIMStream.Position = 0;

      mBWriter.Write((byte)EndianConverter.GetCurrentPlatformEndian());
      mBWriter.Write((Int32)WKB.WKBGeometryTypes.MultiLineString);

      mBWriter.Write(collectionItemsToBinary(_coll, 0));
      return oIMStream.ToArray();
    }





    private static byte[] multiAreaToBinary(GeometryBase geometry)
    {
      //cast to MultiArea first
      MultiArea _coll = (MultiArea)geometry;

      System.IO.MemoryStream oIMStream = new System.IO.MemoryStream();
      System.IO.BinaryWriter mBWriter = new System.IO.BinaryWriter(oIMStream);

      oIMStream.Position = 0;

      mBWriter.Write((byte)EndianConverter.GetCurrentPlatformEndian());
      mBWriter.Write((Int32)WKB.WKBGeometryTypes.MultiPolygon);

      mBWriter.Write(collectionItemsToBinary(_coll, 0));
      return oIMStream.ToArray();
    }


  }
}
